/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author antonio
 */
@Entity
@Table(name = "Era")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Era.findAll", query = "SELECT e FROM Era e"),
    @NamedQuery(name = "Era.findByName", query = "SELECT e FROM Era e WHERE e.name = :name"),
    @NamedQuery(name = "Era.findBySlot", query = "SELECT e FROM Era e WHERE e.slot = :slot")})
public class Era implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "name")
    private String name;
    @Basic(optional = false)
    @NotNull
    @Column(name = "slot")
    private int slot;
    @JoinTable(name = "Availability", joinColumns = {
        @JoinColumn(name = "era", referencedColumnName = "name")}, inverseJoinColumns = {
        @JoinColumn(name = "unit", referencedColumnName = "id")})
    @ManyToMany
    private Collection<Unit> unitCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "era")
    private Collection<Player> playerCollection;

    public Era() {
    }

    public Era(String name) {
        this.name = name;
    }

    public Era(String name, int slot) {
        this.name = name;
        this.slot = slot;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getSlot() {
        return slot;
    }

    public void setSlot(int slot) {
        this.slot = slot;
    }

    @XmlTransient
    public Collection<Unit> getUnitCollection() {
        return unitCollection;
    }

    public void setUnitCollection(Collection<Unit> unitCollection) {
        this.unitCollection = unitCollection;
    }

    @XmlTransient
    public Collection<Player> getPlayerCollection() {
        return playerCollection;
    }

    public void setPlayerCollection(Collection<Player> playerCollection) {
        this.playerCollection = playerCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (name != null ? name.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Era)) {
            return false;
        }
        Era other = (Era) object;
        if ((this.name == null && other.name != null) || (this.name != null && !this.name.equals(other.name))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Era[ name=" + name + " ]";
    }
    
}
